var passed = false;
function num_length(num) {
	var len = 0;
	while(num) {
		num = Math.floor(num / 10);
		len ++;
	}
	return len;
}
function specified_rand(num) {
	return Math.floor(Math.random() * Math.pow(10, num_length(num))) % num;
}
function multiple_rand(num, rand) {
	var ret = [];
	for (loop = 0; loop < num; loop++) {
		ret[loop] = specified_rand(rand);
	}
	return ret;
}
function verify_code() {
	var cases = 5;
	switch(specified_rand(cases)) {
		case 0:
			number = multiple_rand(2, Math.pow(2, 31));
			return [number[0] + "加" + number[1] + "等于？", number[0] + number[1]];
		case 1:
			number = multiple_rand(2, Math.pow(2, 31));
			return [number[0] + "减" + number[1] + "等于？", number[0] - number[1]];
		case 2:
			number = multiple_rand(2, Math.pow(2, 15));
			return [number[0] + "乘" + number[1] + "等于？", number[0] * number[1]];
		case 3:
			number = multiple_rand(2, Math.pow(2, 15));
			return [number[0] + "（整）除" + number[1] + "等于？", Math.floor(number[0] / number[1])];
		case 4:
			number = multiple_rand(2, Math.pow(2, 15));
			return [number[0] + "取余" + number[1] + "等于？", number[0] % number[1]];
	}
}
function check_code() {
	var verify = verify_code();
	if (prompt(verify[0]) != verify[1]) {
		alert("请输入正确的验证码！")
		return false;
	}
	passed = true;
	return true;
}
/* function try_submit(loc) {
	if (passed !== true) return false;
	window.location.href = loc;
	return true;
} */
